import request from '@/utils/request'
import type {
  UserSkill,
  UserSkillSaveOrUpdateParam,
  UserSkillListParam,
  UserSkillDeleteParam,
} from '@/types/user-skill'

/**
 * 获取用户技能列表
 */
export const getUserSkillList = async (userId: number): Promise<UserSkill[]> => {
  const param: UserSkillListParam = { userId }
  return await request({
    url: '/manage/user-skill/list',
    method: 'post',
    data: param,
  })
}

/**
 * 保存或更新用户技能
 */
export const saveOrUpdateUserSkill = async (
  param: UserSkillSaveOrUpdateParam
): Promise<unknown> => {
  return await request({
    url: '/manage/user-skill/saveOrUpdate',
    method: 'post',
    data: param,
  })
}

/**
 * 删除用户技能
 */
export const deleteUserSkill = async (id: number): Promise<unknown> => {
  const param: UserSkillDeleteParam = { id }
  return await request({
    url: '/manage/user-skill/delete',
    method: 'post',
    data: param,
  })
}

/**
 * 批量更新排序
 */
export const updateUserSkillSortOrder = async (
  params: UserSkillSaveOrUpdateParam[]
): Promise<unknown> => {
  return await request({
    url: '/manage/user-skill/updateSortOrder',
    method: 'post',
    data: params,
  })
}
